import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains

#  六月  酒仙网业务流程脚本编写 一
driver=webdriver.Edge()
driver.maximize_window()
driver.get('https://www.jiuxian.com/')
# 隐式等待 2
driver.implicitly_wait(1)
# 请登录  鼠标操作
sbcz=driver.find_element(By.CLASS_NAME,'headerLogin')
# 强制等待 1
time.sleep(3)
# 单击
ActionChains(driver).click(sbcz).perform()
# 双击
ActionChains(driver).double_click(sbcz).perform()

# 手机号  键盘事件
a=driver.find_element(By.NAME,'uname')
a.send_keys("13103053968")
a.send_keys(Keys.ENTER)
time.sleep(3)
# 密码
driver.find_element(By.NAME,'_pwd').send_keys("jiuxianwang123aaa")
time.sleep(10)
# 登录按钮  显示等待 3
WebDriverWait(driver,20,0.5).until(EC.presence_of_element_located((By.ID,'save'))).click()
# driver.find_element(By.ID,'save').click()
# time.sleep(3)
# 点击白酒
driver.find_element(By.XPATH,'//*[@id="_nowactstr2"]/div/h3/a').click()
time.sleep(3)
# 切换窗口
driver.switch_to.window(driver.window_handles[-1])
time.sleep(3)
# 第一个商品  点击列表的商品
driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div[6]/ul/li[1]/div[2]/div[1]/a/img').click()
time.sleep(5)
# 商品详情  收藏
driver.find_element(By.CLASS_NAME,'dIcon').click()
time.sleep(3)
# 商品详情  加入购物车
driver.find_element(By.XPATH,'//*[@id="addToCartForDetail"]').click()
time.sleep(3)
# 查看购物车
driver.find_element(By.CSS_SELECTOR,'.u-buy-go').click()
time.sleep(3)
# 点击去结算
driver.find_element(By.XPATH,'//*[@id="cart_container"]/div[3]/div[3]/a[1]').click()
time.sleep(3)
# 浏览器时间
driver.close()


# yuansu=driver.find_element(By.XPATH,'/html/body/div[8]/div[2]/div[2]/div[2]/ul/li[5]/div[1]/a/img')
# # 打印元素是否显示
# print(yuansu.is_selected())
# # 是否选中
# print(yuansu.is_selected())